package com.example.login.controller;


import com.example.login.entity.Poem;
import com.example.login.repository.PoemRepository;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigInteger;
import java.util.List;
import java.util.Random;

@RestController
@RequestMapping("/poem")
public class PoemController {
    @Resource
    private PoemRepository poemRepository;

    @GetMapping("/all")
    public List<Poem> findall(){
        List<Poem> poemList = poemRepository.findAll();
        System.out.println(poemList);
        return poemList;

    }


    @PostMapping("/select")
    public List<Poem> select(@RequestBody String searchContent){
        Poem poem = new Poem();
        poem.setTitle(searchContent);
        List<Poem> poemlist = poemRepository.findByTitleLike("%" + poem.getTitle() + "%");
        return poemlist;
    }

    @PostMapping("/find")
    public List<Poem> find(@RequestBody String poem){
//        System.out.println(poem);
        List<Poem> poemList = poemRepository.findByDynasty(poem);
//        System.out.println(poemList);
        return poemList;
    }


}
